package x.y.z;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Mapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import x.y.z.mapper.DictTypeMapper;
import x.y.z.model.DictType;

import javax.annotation.Resource;

@SpringBootApplication
@MapperScan("x.y.z.mapper")
@Slf4j
public class MyBatisApp implements CommandLineRunner {
    public static void main(String[] args) {
        SpringApplication.run(MyBatisApp.class, args);
    }


    @Resource
    DictTypeMapper mapper;

    @Override
    public void run(String... args) throws Exception {
        ObjectMapper objectMapper =  new ObjectMapper();
        mapper.getAll().stream().map(obj->{
            try {
                return objectMapper.writeValueAsString(obj);
            } catch (JsonProcessingException e) {
                e.printStackTrace();
            }
            return "";
        }).forEach(log::info);
    }
}
